package demo02;

import java.util.Arrays;
import java.util.Comparator;

public class Demo04LambdaComparator {
    public static void main(String[] args) {
        String[] strings = { "abc", "ab", "abcd" };
        System.out.println(Arrays.toString(strings));
        Arrays.sort(strings, makeComparator());
        System.out.println(Arrays.toString(strings));
    }

    // 使用函数式接口Comparator作为方法返回值类型
    public static Comparator<String> makeComparator() {
        // Lambda作为方法返回值
        return (s1, s2) -> s1.length() - s2.length();
    }
}
